package com.stock.stockana.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import com.stock.publiclib.BaseActivity;
import com.stock.stockana.R;
import com.stock.stockana.ui.fragments.SelectStockFragment;

import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

/**
 * Created by ljgsonx on 2016/1/30.
 */
public class SelectStockActivity extends BaseActivity {

    private final static String TAG = "SelectStockActivity";

    private SelectStockFragment selectStockFragment;

    public static SelectStockActivity instance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        selectStockFragment = new SelectStockFragment();
        addFragment(selectStockFragment);
        setToolbarPosTitle("搜索股票");
        removeToolbarMenu();
        if(getSupportActionBar() != null){
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if(getSupportFragmentManager().getBackStackEntryCount() > 1) {
            getSupportFragmentManager().popBackStackImmediate();
        }else{
            finish();
            overridePendingTransition(R.anim.in_from_left, R.anim.out_from_right);
            instance = null;
            if(MainActivity.instance == null){
                startActivity(new Intent(this, MainActivity.class));
            }
        }
    }

    /**
     * Description: 设置默认字体
     * Author: ljgsonx
     * Time: 2016/2/24 13:58
     */
    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }
}
